package com.freshfresh.activity.selfcenter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;
import com.freshfresh.activity.BaseActivity;
import com.freshfresh.activity.R;
import com.freshfresh.adapter.MyFavoriteAdapter;
import com.freshfresh.utils.FreshConstants;
import com.freshfresh.utils.UrlConstants;
import com.freshfresh.utils.Utils;

public class MyFavoriteActivity extends BaseActivity implements OnClickListener{
	private static int pageIndex = 1;
	private static int pageSize = 10;
	private TextView btn_shoppingcar_info;
	private String categoryid;
	private Context context;
	private ImageView dialog_title_image;
	String goods;
	private GridView gridView;
	private ImageView iv_shoppingcar_add;
	private ImageView iv_shoppingcar_reduction;
	private LinearLayout ll_my_favorite_back;
	private LinearLayout ll_shopping_choice;
	private Context mmContext;
	private String name;
	private int num = 1;
	private float scaleHeight = 1.0F;
	private float scaleWidth = 1.0F;
	int shoppingposition;
	String userid = null;
	String token;
	private List<String> tempList;
	private MyFavoriteAdapter gridAdapter = null;
	private List<Map<String, String>> listMaps;

	private TextView tv_list_title;
	private Dialog dia;
	private Button btn_cancellation;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.ac_my_favorite_list);
		this.context = this;

		gridView = (GridView) findViewById(R.id.gridVieww);

		SharedPreferences sp = FreshConstants
				.getUserShared(MyFavoriteActivity.this);
		userid = sp.getString("userid", "");
		token = sp.getString("token", "");
		// initview();
		initData();
	}

	// @Override
	// protected void onResume() {
	// super.onResume();
	// // setMyActivity(this);
	// // tempList = new ArrayList<String>();
	// initData();
	// }


	private void initData() {
		Map<String, String> localAjaxParams = new HashMap<String, String>();
		localAjaxParams.put("token", token);
		localAjaxParams.put("customerid", userid);
		// localAjaxParams.put("page", pageIndex);
		// localAjaxParams.put("page_size", pageSize);
		localAjaxParams.put("topsize", "");
		localAjaxParams.put("sortType", "");

		dia = Utils.createLoadingDialog(MyFavoriteActivity.this, "正在加载...");
		dia.show();
		executeRequest(new StringRequest(UrlConstants.getWishList,
				localAjaxParams, new Response.Listener<String>() {

					@Override
					public void onResponse(String arg0) {
						dia.dismiss();
						if (Utils.parseJsonStr(arg0).get("result").toString()
								.equals("1")) {
							System.out.println(userid + "+++++" + token);
							Map<String, Object> Maps = (Map<String, Object>) Utils
									.parseJsonStr(arg0).get("data");
							Map<String, Object> map2 = (Map<String, Object>) Maps
									.get("product_list");
							listMaps = (List<Map<String, String>>) map2
									.get("product_info");
							// (List<Map<String, String>>) bundleList =
							// listMaps.get(shoppingposition).get("bundle_list");
							gridAdapter = new MyFavoriteAdapter(context,
									listMaps, userid, token);
							gridView.setAdapter(gridAdapter);
						}
					}
				}, null));
	}

//	private void initview() {
//
//		findViewById(R.id.ll_my_favorite_back).setOnClickListener(this);
//		findViewById(R.id.ib_favorite_fanhui).setOnClickListener(this);
//
//	}

	// private Button ru_dialog_chaozhi;
	// private ShoppingCarDialog carDialog;
	// @Override
	// switch (v.getId()) {
	// case R.id.btn_cancellation:
	// showToast(MyFavoriteActivity.this, "你点击了取消收藏！！");
	// System.out.println("))>>>>>>>>>>>>>>>>>>>>");
	// // shoppingposition = position ;
	// // deleteWishListProduct();//删除收藏
	// break;

	// case R.id.root:// 到详情页面
	//
	// Intent proIntent = new Intent(MyFavoriteActivity.this,
	// ProductDetailsActivity.class);
	// proIntent.putExtra("productid",
	// gridAdapter.getItem(position).getProduct_id());
	// proIntent.putExtra("name",
	// gridAdapter.getItem(position).getName());
	// proIntent.putExtra("price",
	// gridAdapter.getItem(position).getSpecial_price());
	// proIntent.putExtra("image",
	// gridAdapter.getItem(position).getImage());
	// proIntent.putExtra("categoryid",
	// gridAdapter.getItem(position).getCategories());
	// proIntent.putExtra("special_category",
	// gridAdapter.getItem(position).getSpecial_category());
	// startActivity(proIntent);
	// break;
	// case R.id.tv_buy:// 加入购物车

	// View view = LayoutInflater.from(context).inflate(
	// R.layout.dl_shoppingcar_dialog, null);
	// /**
	// * 这是对话框
	// */
	// ru_dialog_chaozhi =
	// (Button)view.findViewById(R.id.ru_dialog_chaozhi);
	// if("simple".equals(tempList.get(position).getType())){
	// ru_dialog_chaozhi.setText(gridAdapter.getItem(position).getStandard2());
	// }
	// carDialog = new ShoppingCarDialog(getMyActivity())
	// .builder(view)
	// .setTitleName(tempList.get(position).getName())
	// .setTitlePrice(StringUtil.formatStringToWish("￥0.00",
	// tempList.get(position).getPrice()))
	// .setStandard(tempList.get(position).getStandard2())
	// .show();
	// /**
	// * 用户图片
	// */
	// dialog_title_image=(ImageView)
	// view.findViewById(R.id.dialog_title_image);
	// final ActiveDetailBean bean = tempList.get(position);
	// ImageLoaderFactory.getImageLoader()
	// .displayImage(bean.getImage(), dialog_title_image
	// , ImageLoaderFactory.generateDefaultDisplayImageOptions());
	//
	// /**
	// * QTY的值
	// */
	// iv_shoppingcar_reduction= (ImageView)
	// view.findViewById(R.id.iv_shoppingcar_reduction);
	// iv_shoppingcar_add= (ImageView)
	// view.findViewById(R.id.iv_shoppingcar_add);
	// ed_shoppingcar_show=(EditText)
	// view.findViewById(R.id.ed_shoppingcar_show);
	// ed_shoppingcar_show.setText("1");
	// iv_shoppingcar_add.setOnClickListener(new OnClickListener() {
	//
	// @Override
	// public void onClick(View v) {
	// num++;
	// ed_shoppingcar_show.setText(Integer.toString(num));
	// }
	// });
	//
	// iv_shoppingcar_reduction.setOnClickListener(new
	// OnClickListener() {
	//
	// @Override
	// public void onClick(View v) {
	// if (num>=2) {
	// num--;
	// ed_shoppingcar_show.setText(Integer.toString(num));
	// }
	// }
	// });

	/**
	 * 加入购物车
	 */
	// btn_shoppingcar_info = (TextView) view
	// .findViewById(R.id.btn_shoppingcar_info);
	// btn_shoppingcar_info
	// .setOnClickListener(new OnClickListener() {
	//
	// @Override
	// public void onClick(View arg0) {
	// carDialog.closeDialog();
	//
	// if (getUserInfo() != null) {
	// AddToShoppingCar();
	// } else {
	//
	// try {
	// ProductDetail productDetail = new ProductDetail();
	// //图片
	// productDetail.setImage(tempList.get(shoppingposition).getImage());
	// //商品名称
	// productDetail.setName(tempList.get(shoppingposition).getName());
	// //商品product_id
	// productDetail.setProduct_id(tempList.get(shoppingposition).getProduct_id());
	//
	// productDetail.setCategories(tempList.get(shoppingposition).getCategories());
	//
	// //商品数量
	// productDetail.setQty(Integer.toString(num));
	// //商品价格
	// productDetail.setPrice(tempList.get(shoppingposition).getSpecial_price());
	//
	// Boolean isShoppingBool =
	// LocalDataForShoppingCarWithSharedPreferenceUtil
	// .isTheNumberOfGoodsInShopppingCarAlreadyGoingToMaxValue();
	// //
	// if (isShoppingBool == false) {
	// ProductDetail detail =
	// LocalDataForShoppingCarWithSharedPreferenceUtil.getGoodById(productDetail
	// .getProduct_id());
	// if (detail == null) {
	// Boolean shoppingcarReturn =
	// LocalDataForShoppingCarWithSharedPreferenceUtil
	// .addNewOneToLocalData(productDetail);
	// if (shoppingcarReturn == true) {
	// ToastUtil.showToast("商品已加入购物车");
	//
	// gridAdapter.update(shoppingposition);
	// gridAdapter.notifyDataSetChanged();
	// } else {
	// ToastUtil.showToast("加入购物车失败");
	// }
	// } else {
	// int qty = Integer.parseInt(detail.getQty()) +
	// Integer.parseInt(productDetail.getQty());
	// productDetail.setQty(qty + "");
	//
	// boolean isUpdateNewOne =
	// LocalDataForShoppingCarWithSharedPreferenceUtil
	// .updateNewOne(productDetail);
	// if (isUpdateNewOne) {
	// ToastUtil.showToast("商品已加入购物车");
	// gridAdapter.update(shoppingposition);
	// gridAdapter.notifyDataSetChanged();
	// } else {
	// ToastUtil.showToast("加入购物车失败");
	// }
	// }
	// } else {
	// ToastUtil.showToast("您的购物车商品太多了，请先去结算吧");
	// }
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// }
	// }
	// });
	//
	// break;

	@Override
	public void onClick(View v) {

		switch (v.getId()) {

		}

	}

}